/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package commons.io.FileUtils;

import java.io.File;
import org.apache.commons.io.FileUtils;

/**
 *
 * @author WangShuai
 */
public class Demo1 {
    public static void main(String[] args) throws Exception{
        //1.List the available filesystem roots.
//        File[] files = File.listRoots();
//        System.out.println("length:" + files.length);
//        for(File file : files) {
//            System.out.print(file.getAbsolutePath()); //length:6  C:\D:\E:\X:\Y:\Z:\
//        }

        //2.创建目录
        //File file = new File("C:\\test\\test2");
        //目录已存在，创建失败
        //System.out.println("mkdir: "+file.mkdir());   //只能创建1级
        //System.out.println("mkdir: "+file.mkdirs());   //能够创建多级

        //FileUtils.forceMkdir(file);     //使用commons-io工具，内部调用mkdirs

        //3.移动文件
        //3.1Dir to Dir {整个目录移动到目标目录，包括源目录自身}
        File srcDir = new File("C:\\test");
        File targetDir = new File("C:\\temp");
        //FileUtils.moveDirectoryToDirectory(srcDir, targetDir, true);

        //3.2 File to Dir{移动一个文件到目标目录}
        File srcFile = new File("C:\\2.csv");
        //FileUtils.moveFileToDirectory(srcDir, targetDir, true);  //throw FileNotFoundException;Because srcDir is a Dir,not a file
        //FileUtils.moveFileToDirectory(srcFile, targetDir, true);

        //3.3 File or dir to Dir
        //FileUtils.moveToDirectory(srcDir, targetDir, true);

        //3.4 Dir  turns  Dir{源目录变为目标目录，非移动到目标目录中}
        File targetMoveDir = new File("C:\\test2");
        //FileUtils.moveDirectory(srcDir, targetDir);  // throw IOException;Destination 'C:\temp' already exists
        //FileUtils.moveDirectory(srcDir, targetMoveDir);

        //4.复制文件
        //4.1 File to Dir
        //FileUtils.copyFileToDirectory(srcFile, targetDir, true);
        //FileUtils.copyFileToDirectory(srcDir, targetDir, true);   //throw FileNotFoundException;Because srcDir is a Dir,not a file


    }
}
